package com.chenglai.seckill.controller;

import com.chenglai.commonutils.common.Result;
import com.chenglai.commonutils.common.StatusCode;
import com.chenglai.seckill.entity.MainOrder;
import com.chenglai.seckill.service.GroupOnInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author yawang
 * @create 2023/11/29 08:47:32
 **/
@RestController
@RequestMapping("/group")
@Api(value = "/group", tags = {"团购"})
public class GroupController {
    @Autowired
    private GroupOnInfoService groupOnInfoService;

    @PostMapping("/listGroupGoods")
    @ApiOperation(value = "获取团购商品列表")
    public Result listGroupGoods(Integer shopId){
        try {
            return groupOnInfoService.listGroupGoods(shopId);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, StatusCode.OK,"获取失败");
        }
    }

//    @PostMapping("/startGroup")
//    @ApiOperation(value = "开团")
//    public Result startGroup(@ApiParam(name="shopId",value = "门店ID")Integer shopId,
//                             @ApiParam(name="userId",value = "用户ID")Integer userId,
//                             @ApiParam(name="groupId",value = "如果开团，则传groupId,拼团则传团ID")Integer groupId,
//                             @ApiParam(name="goodsId",value = "商品ID")Integer goodsId,
//                             @ApiParam(name="flag",value = "0为开团,1为拼团")Integer flag,
//                             @ApiParam(name="groupNum",value = "几人团")Integer groupNum){
//        try {
//            Map map = groupOnInfoService.startGroup(shopId,userId,groupId,goodsId,flag, groupNum);
//            return new Result(true, StatusCode.OK,"获取失败",map);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return new Result(true, StatusCode.OK,"获取失败");
//        }
//    }

    @PostMapping("/startGroup")
    @ApiOperation(value = "开团")
    public Result startGroup(MainOrder mainOrder,
                             @ApiParam(name="flag",value = "1为开团,2为拼团")Integer flag,
                             @ApiParam(name="groupId",value = "如果开团，则传groupId,拼团则传团ID")Integer groupId,
                             @ApiParam(name="groupNum",value = "几人团")Integer groupNum){
        try {
            return groupOnInfoService.startGroup(mainOrder,groupId,flag, groupNum);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, StatusCode.OK,"获取失败");
        }
    }


    @PostMapping("/addGroupOnOrDetail")
    @ApiOperation(value = "添加主团信息以及团购详情")
    public Result addGroupOnOrDetail(Map map){
        try {
            Map maps =  groupOnInfoService.addGroupOnOrDetail(map);
            return new Result(true, StatusCode.OK,"成功",maps);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, StatusCode.OK,"获取失败");
        }
    }


}
